home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / tclX-6.4 / help / control / case < prev    next >
Encoding:
Text File  |  1992-12-17  |  2.5 KB  |  57 lines

  1.           case string ?in? patList body ?patList body ...?
  2.  
  3.           case string ?in? {patList body ?patList body ...?}
  4.                Match string against each of the patList  arguments  in
  5.                order.   If  one  matches,  then evaluate the following
  6.                body argument by passing  it  recursively  to  the  Tcl
  7.                interpreter,  and return the result of that evaluation.
  8.                Each patList argument consists of a single  pattern  or
  9.                list  of patterns.  Each pattern may contain any of the
  10.                wild-cards described under string match.  If a  patList
  11.                argument  is  default,  the  corresponding body will be
  12.                evaluated if no patList matches string.  If no  patList
  13.                argument  matches  string and no default is given, then
  14.                the case command returns an empty string.
  15.  
  16.                Two syntaxes are provided.  The first uses  a  separate
  17.                argument  for  each  of the patterns and commands; this
  18.                form is convenient if substitutions are desired on some
  19.                of  the  patterns  or commands.  The second form places
  20.                all of the patterns and commands together into a single
  21.                argument; the argument must have proper list structure,
  22.                with the elements of the list being  the  patterns  and
  23.                commands.   The  second form makes it easy to construct
  24.                multi-line case commands, since the braces  around  the
  25.                whole  list  make it unnecessary to include a backslash
  26.                at the end of each line.  Since the  patList  arguments
  27.                are  in  braces  in  the  second  form,  no  command or
  28.                variable substitutions are  performed  on  them;   this
  29.                makes  the  behavior  of the second form different than
  30.                the first form in some cases.
  31.  
  32.                Below are some examples of case commands:
  33.  
  34.                  case abc in {a b} {format 1} default {format 2} a* {format 3}
  35.  
  36.                will return 3,
  37.  
  38.                     case a in {
  39.                       {a b} {format 1}
  40.                       default {format 2}
  41.                       a* {format 3}
  42.                     }
  43.  
  44.                will return 1, and
  45.  
  46.                     case xyz {
  47.                       {a b}
  48.                         {format 1}
  49.                       default
  50.                         {format 2}
  51.                       a*
  52.                         {format 3}
  53.                     }
  54.  
  55.                will return 2.
  56.  
  57.